home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
DEMOS
/
SWARS
/
!Swars
/
!Help
< prev
next >
Wrap
Text File
|
1996-03-17
|
3KB
|
82 lines
/********************************************************************/
/* -=[FlY'96]=- presents !Swars a StarWars scroller tutorial ...*/
/********************************************************************/
Yeah third production :)
This piece of code demonstrate the starwars scrolling effect.
I include the sources (in C) for you all other beginner that maybe
wanted to code such little things ;)
Ok let's have a bit of explanations:
This effect is mainly based on the shifted step principle
(also called fixed point).So what's fixed point ???
The f.p method consists in precalculating the manneer of how
you will read the image to display it.have an example :
+--------+ +---+ if you want to display image A but
| A | | B | into B box on screen with keeping
| | | | the appearance of A, you'll have to
+--------+ +---+ read 1 pixel on 2 for each line of
A ... Why ? line length of A is 10 and of B is 5 so the
mathematics is simple 10/5=2 so it's simple you read 1
then skip one , then read 1 then skip one...
You will then do read p1 read p3 read p5 ...p[i] p[i+2]
and 2 come from the 10/5 ! Got it ?
So why to shift the step ? just becoz we work on integers
and that if we got step=0.5 we will always read the pixel
0 of each line wich will look awful ...
The trick is then : (A_linelenght LSL by 8)/B_linelength
after that you'll always have to shift back (LSR) by 8 too.
note that you'll need a variable to sum the steps (LSR) at
each steps of the loop ...
So the starwars is only a triangle on wich we deform a picture
simply by calculating a step for each line of the triangle.
we have a start point for each line and also a line length.
All we have to do is (for each line) :
go to start point at the screen.
accumulator=0;
for i=0 to triangle_linelength
{
read pixel in buffer from xposition;
accumulator+=step_for_this_line;
xposition <- (accumulator) >> 8;
display pixel at position_to_screen;
position_to_screen+=1;
}
And that's all (well i guess , I don't look my code :)... )
IF this is not clear feel free to email me ( that's not very clear but
I've at least tried to explain the effect ) but hqve first a look to the
C source code , it's quiet self-explaining ...
SORRY:
The present code is not that fast becoz it's not ARM pure juice.
Sorry about that... It may then not run very smoothly on many
Acorns ... It runs ok (slow) on my A5000 but I don't know for the
other machines...
NOTE:
*This little demo is mostly intended for beginners like me that have
always wanted to have sources to understand the effects and maybe
(who knows ?) become one day a good coder :)
*As you can see in the code you can deform the picture on other
objects than triangles if you define them well (no 0<= in p.stop)...
GREETINGS:
Just want to say hello to some friends around: Daniel who greatly
helped me in my first steps, Armoric the master of 3Kb Basic ARM
powered effects :) , BASS (lo John, Karl, Gil and the others...),
And all the demo scene (if there is any ...;) ) !
Plus all the friends in the scrolly :)
ADDRESS:
if u want just drop me a mail to ahuet@ulb.ac.be ...
( available to august 96 at least )
<EOF>